package com.jeeplus.organization.controller;

import com.jeeplus.aop.logging.annotation.ApiLog;
import com.jeeplus.organization.service.ChartService;
import com.jeeplus.organization.service.dto.SexChartDTO;
import com.jeeplus.organization.service.dto.StatusChartDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 图表展示Controller
 *
 * @author jeeplus
 * @version 2024-5-28
 */
@Api(tags = "图表展示")
@RestController
@RequestMapping("/organization/ratio")
public class ChartController {

    @Autowired
    private ChartService chartService;

    /**
     * 查询列表
     *
     * @param postId
     * @return
     */
    @ApiLog("查询性别比")
    @ApiOperation(value = "查询性别比")
    @PreAuthorize("hasAuthority('organization:ratio:sex')")
    @GetMapping("sex")
    public ResponseEntity<SexChartDTO> selectSexRatio(@RequestParam("postId") String postId){
        Integer male = chartService.selectSexRatio(postId, "男");
        Integer female = chartService.selectSexRatio(postId, "女");
        Integer total = chartService.selectSexRatio(postId, "");
        return ResponseEntity.ok( new SexChartDTO(male,female,total));
    }

    /**
     * 查询在职状态
     *
     * @param postId
     * @return
     */
    @ApiLog("查询在职状态")
    @ApiOperation(value = "查询在职状态")
    @PreAuthorize("hasAuthority('organization:ratio:status')")
    @GetMapping("status")
    public ResponseEntity<StatusChartDTO> selectStatusRatio(@RequestParam("postId") String postId){
        String on = chartService.selectStatusRatio(postId, "是");
        String off = chartService.selectStatusRatio(postId, "否");
        String total = chartService.selectStatusRatio(postId, "");
        return ResponseEntity.ok( new StatusChartDTO(on,off,total));
    }
}
